package wlf.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import wlf.pojo.Admin;

@Controller
public class AdminLoginController {
	@RequestMapping("/toLogin")
	public ModelAndView toLogin(){
		ModelAndView model = new ModelAndView("/WEB-INF/backstage/login.jsp");
		return model;
	}
	@RequestMapping("/login")
	public ModelAndView login(HttpServletRequest request){
		ModelAndView model = new ModelAndView("/toLogin");
		System.out.println(request.getAttribute("shiroLoginFailure"));
		return model;
	}
	@RequestMapping("/toIndex")
	public ModelAndView toIndex(HttpSession session){
		ModelAndView model = new ModelAndView("/WEB-INF/backstage/index.jsp");
		Subject subject = SecurityUtils.getSubject();
		Admin admin = (Admin)subject.getPrincipal();
		session.setAttribute("admin", admin);
		return model;
	}
	
}
